home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
gnulib
/
gnulib3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-26
|
2KB
|
102 lines
typedef struct set_vector
{
int length;
int vector[1];
/* struct set_vector *next; */
} set_vector;
#ifdef sprite
set_vector __CTOR_LIST__;
set_vector __DTOR_LIST__;
static set_vector *__dlp;
static int __dli;
int __1xyzzy__;
#else
extern set_vector __CTOR_LIST__;
extern set_vector __DTOR_LIST__;
set_vector *__dlp;
int __dli;
#endif
extern void exit ();
extern void __do_global_init ();
extern void __do_global_cleanup ();
extern void on_exit(void*, void*);
#if defined(i386) && !defined(sequent)
#define COFF
#endif
#ifdef COFF_ENCAPSULATE
#undef COFF
#endif
#if defined(sprite)
#define ON_EXIT(PROCP) \
do { extern void PROCP (); atexit (PROCP); } while (0)
#endif
int
__main ()
{
/* Gross hack for GNU ld. This is defined in `builtin.cc'
from libg++. */
#ifndef COFF
extern int __1xyzzy__;
#endif
#ifdef ON_EXIT
#ifdef sprite
ON_EXIT (_cleanup);
#endif
ON_EXIT (__do_global_cleanup);
#endif
__dli = __DTOR_LIST__.length;
__dlp = &__DTOR_LIST__;
#ifndef COFF
__do_global_init (&__1xyzzy__);
#else
__do_global_init ();
#endif
}
#ifndef ON_EXIT
void
exit (status)
int status;
{
__do_global_cleanup ();
_cleanup ();
_exit (status);
}
#endif
void
__do_global_init ()
{
register int i, len;
register void (**ppf)() = (void (**)())__CTOR_LIST__.vector;
len = __CTOR_LIST__.length;
for (i = 0; i < len; i++)
(*ppf[i])();
}
void
__do_global_cleanup ()
{
while (__dlp)
{
while (--__dli >= 0)
{
void (*pf)() = (void (*)())__dlp->vector[__dli];
(*pf)();
}
__dlp = (struct set_vector *)__dlp->vector[__dlp->length];
if (__dlp) __dli = __dlp->length;
}
}